import numpy as np


class DataSet:
    def __init__(self):
        # 二维向量，横轴是分片，纵轴是时隙
        self.bitratelevel = []
        self.bitrateInfo = []
        self.buffer = []
        self.FovRecord = []
        self.rebuffer_time = []
        self.throughput = []
        self.pause_total = []
        self.name = ""

    def Fetch_data_from_file(self, filepath, filename):
        pos = []
        file = filepath + filename
        with open(file, 'r') as file_to_read:
            while True:
                lines = file_to_read.readline()  # 整行读取数据
                if not lines:
                    break
                p_tmp = [float(i) for i in lines.split(',')]  # 将整行数据分割处理，如果分割符是空格，括号里就不用传入参数，如果是逗号， 则传入‘，'字符。
                pos.append(p_tmp)  # 添加新读取的数据
            pos = np.array(pos)
        if filename == "bitrateLevel.txt":
            self.bitratelevel = pos
        elif filename == "bitrateInfo.txt":
            self.bitrateInfo = pos
        elif filename == "throughput.txt":
            self.throughput = pos
        elif filename == "buffer.txt":
            self.buffer = pos
        elif filename == "FovRecord.txt":
            self.FovRecord = pos
        elif filename == "pause_total.txt":
            self.pause_total = pos
        elif filename == "rebuffer_time.txt":
            self.rebuffer_time = pos
